/* 
 * File:   motor_main.c
 * Author: Toanpv
 *
 * Created on May 6, 2014, 10:48 PM
 */


// PIC16F886 Configuration Bit Settings

// 'C' source line config statements

#include <htc.h>
#include "pwm.h"

__CONFIG(FOSC_HS & WDTE_OFF & PWRTE_OFF & MCLRE_OFF & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF);
__CONFIG(BOR4V_BOR40V & WRT_OFF);



/*
 * 
 */
int main()
{
	int i = 0;
	float duty_val = 0;
	pwm1_init(1000, SingleMode);
	pwm2_init(1000);

	pwm1_start(0);
	pwm2_start(0);
	
	while(1)
	{
		for(i = 0; i <= 100; i++)
		{
			duty_val = (float)i/100;
			pwm1_set_duty(duty_val);
			delay_ms(100);
		}
		for(i = 100; i >= 0; i--)
		{
			duty_val = (float)i/100;
			pwm1_set_duty(duty_val);
			delay_ms(100);
		}

		delay_ms(2000);

		for(i = 0; i <= 100; i++)
		{
			duty_val = (float)i/100;
			pwm2_set_duty(duty_val);
			delay_ms(100);
		}
		for(i = 100; i >= 0; i--)
		{
			duty_val = (float)i/100;
			pwm2_set_duty(duty_val);
			delay_ms(100);
		}
		delay_ms(2000);
	}
	return 0;
}

